﻿package com.pandemicode.framework.localization {
	/**
	* @author Michael Lawrence
	* @version 1.0.0
	*/
	public class LocaleString {
		private var _id:String;
		private var _value:String;
		
		/**
		 * The ID of the locale string.
		 */
		public function get id():String { return this._id; }
		
		/**
		 * The Value of the locale string.
		 */
		public function get value():String { return this._value; }
		
		/**
		 * A class that maps an ID with a string Value.
		 * @param	id		The ID of the locale string.
		 * @param	value	The Value of the locale string.
		 */
		public function LocaleString(id:String, value:String) {
			this._id = id;
			this._value = value;
		}
		
		/**
		 * Creates a locale string from an XML object.
		 * @param	xmlNode		The XML object to convert to a LocaleString.
		 * @return	Returns a locale string from an XML object.
		 */
		public static function fromXML(xmlNode:XML):LocaleString {
			return new LocaleString(String(xmlNode.@id), String(xmlNode.text()));
		}
		
		/**
		 * Creates an array of locale strings from an XMLList.
		 * @param	xmlList		The XMLList to convert to an array of LocaleStrings.
		 * @return	Returns an array of locale strings from an XMLList.
		 */
		public static function fromXMLList(xmlList:XMLList):Array {
			var a:Array = new Array();
			for each(var x:XML in xmlList)
				a.push(fromXML(x));
			return a;
		}
		
		/**
		 * Overrides the default toString method to display more information.
		 * @return	A string representation of the LocaleString object.
		 */
		public function toString():String {
			return "[object LocaleString]\n\tID: " + this._id + "\n\tValue: " + this._value;
		}
	}
}
